// 测试自动匹配功能
import axios from 'axios';

// 模拟前端环境
const modelIdData = [
  { m_id: 101011000, m_name: "经典刀锋皮肤", m_occupation: "bladePoint" },
  { m_id: 101011001, m_name: "血腥玛丽", m_occupation: "bladePoint" },
  { m_id: 101011002, m_name: "王女艾琳", m_occupation: "bladePoint" },
  { m_id: 101011003, m_name: "捕猎少女欧丽莎", m_occupation: "bladePoint" },
  { m_id: 101011004, m_name: "炫彩之影·曼尼莎", m_occupation: "bladePoint" },
  { m_id: 101011005, m_name: "泳衣刀锋", m_occupation: "bladePoint" },
  { m_id: 101011006, m_name: "灵魂圣女·柯莉丝汀", m_occupation: "bladePoint" },
  { m_id: 101011007, m_name: "烈焰女皇", m_occupation: "Flame" },
  { m_id: 101011008, m_name: "火焰舞者", m_occupation: "Flame" },
  { m_id: 101011009, m_name: "双枪手", m_occupation: "doubleGun" }
];

// 根据模型名称动态匹配model_id
const matchModelId = (modelName) => {
  console.log('matchModelId called with:', modelName);
  console.log('Available modelIdData:', modelIdData);
  
  if (!modelName || !modelIdData.length) {
    console.log('No modelName or no modelIdData available');
    return null;
  }
  
  // 精确匹配
  let match = modelIdData.find(item => item.m_name === modelName);
  if (match) {
    console.log('Exact match found:', match);
    return match;
  }
  
  // 模糊匹配
  match = modelIdData.find(item => 
    modelName.includes(item.m_name) || item.m_name.includes(modelName)
  );
  if (match) {
    console.log('Fuzzy match found:', match);
    return match;
  }
  
  // 关键词匹配
  const keywords = modelName.split(/[\s\-·]+/);
  console.log('Keywords extracted:', keywords);
  for (const keyword of keywords) {
    if (keyword.length > 1) {
      match = modelIdData.find(item => 
        item.m_name.includes(keyword)
      );
      if (match) {
        console.log('Keyword match found:', match, 'for keyword:', keyword);
        return match;
      }
    }
  }
  
  console.log('No match found');
  return null;
};

// 测试用例
const testCases = [
  "经典刀锋皮肤",           // 精确匹配
  "血腥玛丽",              // 精确匹配
  "经典刀锋",              // 模糊匹配
  "刀锋",                  // 关键词匹配
  "烈焰女皇",              // 精确匹配
  "火焰",                  // 关键词匹配
  "双枪手",                // 精确匹配
  "不存在的模型",           // 无匹配
  "泳衣",                  // 关键词匹配
  "灵魂圣女",               // 模糊匹配
];

console.log('=== 自动匹配功能测试 ===\n');

testCases.forEach((testCase, index) => {
  console.log(`测试 ${index + 1}: "${testCase}"`);
  const result = matchModelId(testCase);
  if (result) {
    console.log(`✅ 匹配成功: ${result.m_name} (ID: ${result.m_id}, 职业: ${result.m_occupation})`);
  } else {
    console.log(`❌ 无匹配结果`);
  }
  console.log('---');
});

// 测试API调用
async function testAPI() {
  try {
    console.log('\n=== 测试API调用 ===');
    const response = await axios.get('http://localhost:8080/api/v2/model/modelIds');
    console.log('API响应状态:', response.status);
    console.log('API响应数据:', response.data);
  } catch (error) {
    console.log('API调用失败:', error.message);
  }
}

// 如果直接运行此脚本，则执行API测试
testAPI();
